<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        {css file="bootstrap" /}
        {css file="jqueryUI.bootstrap" /}
        {js file="jquery" /}
        {js file="jquery.validate" /}
        {js file="__ROOT__/public/js/jqueryValidate/jquery.metadata.js" /}
        <!--[if lt IE 9]>
                <script src="__ROOT__/public/js/html5.js"></script>
        <![endif]-->
        {js file="jqueryUI.dialog" /}
        <style type="text/css">
            .form-horizontal{
                margin-top:10px;
            }
            .form-horizontal .control-group{
                margin-left: -30px;
                margin-bottom: 10px;
            }
        </style>
    </head>
    <body>
        <div id="model_list">
            <table class="table table-striped table-bordered">
                <tr>
                    <th width="2%">ID</th>
                    <th width="15%">模型表名</th>
                    <th width="10%">模型名</th>
                    <th width="25%">模型描述</th>
                    <th width="10%">模型类别</th>
                    <th width="30%">操作</th>
                </tr>
                {foreach from="$model_list" value="$model"}
                <tr>
                    <td>{$model.dmid}</td>
                    <td>{$model.name}</td>
                    <td>{$model.title}</td>
                    <td>{$model.des}</td>
                    <td>{$model.model_category.0.cate_title}</td>
                    <td>
                        <a class="btn btn-mini" href="__CONTROL__/addField/tableName/{$model.name}/dmid/{$model.dmid}"><i class="icon-plus-sign"></i>增加字段</a>
                        <a class="btn btn-mini" href="__CONTROL__/fieldList/dmid/{$model.dmid}/tableName/{$model.name}"><i class="icon-list"></i>字段管理</a>
                        <a class="btn btn-mini edit-model" is-validate="{$model.validate}" is-upload="{$model.upload}" href="__CONTROL__/editModel/dmid/{$model.dmid}" issue-tpl="{$model.issue_tpl}" edit-tpl="{$model.edit_tpl}"><i class="icon-edit"></i>修改</a>
                        {if value="$model.is_sys==1"}
                        <a class="btn btn-mini " title="系统模型，禁止删除！"><i class="icon-trash"></i>删除模型</a>
                        {else /}
                        <a class="del btn btn-mini btn-danger" href="__CONTROL__/delModel/dmid/{$model.dmid}"><i class="icon-trash icon-white"></i>删除模型</a>
                        {/if}
                    </td>
                </tr>
                {/foreach}
            </table>
            <dvi id="dialog" style="display:none" title="修改模型">
                <form action="" class="well form-horizontal" id="edit-form" validate="true" method="post">
                    <div class="control-group">
                        <label for="title" class="control-label">模型别名</label>
                        <div class="controls">
                            <input type="text" name="title" id="title" validate="{required:true}" />
                            <p class="help-block">输入模型的中文名称</p>
                        </div>
                    </div>
                     <div class="control-group">
                        <label class="control-label" for="issue_tpl">发布模板</label>
                        <div class="controls">
                            <select name="issue_tpl" id="issue_tpl" validate="{required:true}">
                                <option value="">请选择</option>
                                    {foreach from="$model_tpl" value="$tpl"}
                                        <option value="{$tpl.name}">{$tpl.name}</option>
                                    {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="edit_tpl">修改模板</label>
                        <div class="controls">
                            <select name="edit_tpl" id="edit_tpl" validate="{required:true}">
                                <option value="">请选择</option>
                                    {foreach from="$model_tpl" value="$tpl"}
                                        <option value="{$tpl.name}">{$tpl.name}</option>
                                    {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">表单验证</label>
                        <div class="controls">
                            <label class="radio inline">
                                <input type="radio" class="radio" value="1" name="validate">开启</label>
                            <label class="radio inline">
                                <input type="radio" class="radio" value="0" name="validate">关闭</label>
                            <p class="help-block">开启表单验证可以过滤一些格式不正确的数据，建议开启。</p>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">文件上传</label>
                        <div class="controls">
                            <label class="radio inline">
                                <input type="radio" class="radio" value="1" name="upload">开启</label>
                            <label class="radio inline">
                                <input type="radio" class="radio" value="0" name="upload">关闭</label>
                            <p class="help-block">开启后支持上传文件。</p>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="des">模型描述</label>
                        <div class="controls">
                            <textarea class="input-xlarge" name="des" id="des" rows="3"></textarea>
                        </div>
                    </div>
                </form>
            </dvi>
        </div>
        <script>
            $(".ui-table-list tr").hover(function(){
                $("#model_list table tr").css({'backgroundColor':'#FFF'});
                $(this).css({'backgroundColor':'#ddd'});
            })
            $("#model_list .del").click(function(){
                if(confirm('确认删除此模型？\n提示：不会删除数据表。')){
                    location.href=$(this).attr('href');
                }
                return false;
            });
            $("#model_list .edit-model").click(function(){
                $("#edit-form").attr('action',$(this).attr('href'));
                var _validate=$(this).attr('is-validate'),
                _upload=$(this).attr('is-upload'),
                _model_title=$(this).parent().siblings('td:eq(2)').text(),
                _model_desc=$(this).parent().siblings('td:eq(3)').text();
                $("#edit-form input[name='validate'][value='"+_validate+"']").attr('checked',true);
                $("#edit-form input[name='upload'][value='"+_upload+"']").attr('checked',true);
                $("#issue_tpl").val($(this).attr('issue-tpl'));
                $("#edit_tpl").val($(this).attr('edit-tpl'));
                $("#des").val(_model_desc);
                $("#dialog").dialog({width:450,buttons:{
                        '修改':function(){
                            $("#edit-form").submit();
                        },
                        '关闭':function(){
                            $(this).dialog('close');
                        }
                    }});
                $("#title").val(_model_title).focus();
                return false;
            });
        </script>
    </body>
</html>
